﻿<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>学校食堂安全管理系统v1.0</title>

    <!-- Bootstrap Core CSS -->
    <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="../vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- DataTables CSS -->
    <link href="../vendor/datatables-plugins/dataTables.bootstrap.css" rel="stylesheet">

    <!-- DataTables Responsive CSS -->
    <link href="../vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="../dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="../vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="../dist/css/extendcss.css" />
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>
    <div id="wrapper">
        <!-- Navigation -->
        <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle </span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <!-- /.navbar-header -->

            <ul class="nav navbar-top-links navbar-right">
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-envelope fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-messages">
                        <li>
                            <a href="#">
                                <div>
                                    <strong>John Smith</strong>
                                    <span class="pull-right text-muted">
                                        <em>Yesterday</em>
                                    </span>
                                </div>
                                <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <strong>John Smith</strong>
                                    <span class="pull-right text-muted">
                                        <em>Yesterday</em>
                                    </span>
                                </div>
                                <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <strong>John Smith</strong>
                                    <span class="pull-right text-muted">
                                        <em>Yesterday</em>
                                    </span>
                                </div>
                                <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a class="text-center" href="#">
                                <strong>Read All Messages</strong>
                                <i class="fa fa-angle-right"></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-messages -->
                </li>
                <!-- /.dropdown -->
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-tasks fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-tasks">
                        <li>
                            <a href="#">
                                <div>
                                    <p>
                                        <strong>Task 1</strong>
                                        <span class="pull-right text-muted">40% Complete</span>
                                    </p>
                                    <div class="progress progress-striped active">
                                        <div class="progress-bar progress-bar-success" role="progressbar"
                                            aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%">
                                            <span class="sr-only">40% Complete (success)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <p>
                                        <strong>Task 2</strong>
                                        <span class="pull-right text-muted">20% Complete</span>
                                    </p>
                                    <div class="progress progress-striped active">
                                        <div class="progress-bar progress-bar-info" role="progressbar"
                                            aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">
                                            <span class="sr-only">20% Complete</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <p>
                                        <strong>Task 3</strong>
                                        <span class="pull-right text-muted">60% Complete</span>
                                    </p>
                                    <div class="progress progress-striped active">
                                        <div class="progress-bar progress-bar-warning" role="progressbar"
                                            aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%">
                                            <span class="sr-only">60% Complete (warning)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <p>
                                        <strong>Task 4</strong>
                                        <span class="pull-right text-muted">80% Complete</span>
                                    </p>
                                    <div class="progress progress-striped active">
                                        <div class="progress-bar progress-bar-danger" role="progressbar"
                                            aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%">
                                            <span class="sr-only">80% Complete (danger)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a class="text-center" href="#">
                                <strong>See All Tasks</strong>
                                <i class="fa fa-angle-right"></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-tasks -->
                </li>
                <!-- /.dropdown -->
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-bell fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-alerts">
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-comment fa-fw"></i> New Comment
                                    <span class="pull-right text-muted small">4 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-twitter fa-fw"></i> 3 New Followers
                                    <span class="pull-right text-muted small">12 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-envelope fa-fw"></i> Message Sent
                                    <span class="pull-right text-muted small">4 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-tasks fa-fw"></i> New Task
                                    <span class="pull-right text-muted small">4 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-upload fa-fw"></i> Server Rebooted
                                    <span class="pull-right text-muted small">4 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a class="text-center" href="#">
                                <strong>See All Alerts</strong>
                                <i class="fa fa-angle-right"></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-alerts -->
                </li>
                <!-- /.dropdown -->
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        <li><a href="#"><i class="fa fa-user fa-fw"></i> User Profile</a>
                        </li>
                        <li><a href="#"><i class="fa fa-gear fa-fw"></i> Settings</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="login.html"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
                        </li>
                    </ul>
                    <!-- /.dropdown-user -->
                </li>
                <!-- /.dropdown -->
            </ul>
            <!-- /.navbar-top-links -->

            <div class="navbar-default sidebar" role="navigation">
                <div class="sidebar-nav navbar-collapse">
                    <ul class="nav" id="side-menu">
                        <!--<li class="sidebar-search">
                            <div class="input-group custom-search-form">
                                <input type="text" class="form-control" placeholder="Search...">
                                <span class="input-group-btn">
                                <button class="btn btn-default" type="button">
                                    <i class="fa fa-search"></i>
                                </button>
                            </span>
                            </div>
                        </li>-->
                        <li>
                            <a href="#"><i class="fa fa-bar-chart-o fa-fw"></i> 库存管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li>
                                    <a href="receiptplanlist.html">进货计划</a>
                                </li>
                                <li>
                                    <a href="signlist.html">进货签收</a>
                                </li>
                                <li>
                                    <a href="boundin.html">入库管理</a>
                                </li>
                                <li>
                                    <a href="boundout.html">出库管理</a>
                                </li>
                                <li>
                                    <a href="inventory.html">盘点管理</a>
                                </li>
                            </ul>
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-bar-chart-o fa-fw"></i> 供货管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li>
                                    <a href="ghsend.html">送货单管理</a>
                                </li>
                                <li>
                                    <a href="ghreceive.html">收款单管理</a>
                                </li>
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-wrench fa-fw"></i> 财务管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li>
                                    <a href="cwreceive.html">收款管理</a>
                                </li>
                                <li>
                                    <a href="cwpay.html">付款管理</a>
                                </li>
                            </ul>
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-wrench fa-fw"></i> 统计分析<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li>
                                    <a href="tjin.html">进货单查询</a>
                                </li>
                                <li>
                                    <a href="tjout.html">出库汇总表</a>
                                </li>
                                <li>
                                    <a href="tjinsum.html">入库汇总表</a>
                                </li>
                                <li>
                                    <a href="tjhasdetail.html">存货明细账</a>
                                </li>
                                <li>
                                    <a href="tjshouldpay.html"> 应付货款报告</a>
                                </li>
                                <li>
                                    <a href="tjsource.html">食材来源统计</a>
                                </li>
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-sitemap fa-fw"></i>基础数据<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li>
                                    <a href="unitlist.html">单位管理</a>
                                </li>
                                <li>
                                    <a href="supplierlist.html">供应商管理</a>
                                </li>
                                <li>
                                    <a href="foodclasslist.html">菜品类别</a>
                                </li>
                                <li>
                                    <a href="foodlist.html">菜品管理</a>
                                </li>
                                <!--<li>
                                    <a href="#">Third Level <span class="fa arrow"></span></a>
                                    <ul class="nav nav-third-level">
                                        <li>
                                            <a href="#">Third Level Item</a>
                                        </li>
                                        <li>
                                            <a href="#">Third Level Item</a>
                                        </li>
                                        <li>
                                            <a href="#">Third Level Item</a>
                                        </li>
                                        <li>
                                            <a href="#">Third Level Item</a>
                                        </li>
                                    </ul>                                   
                                </li>-->
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-files-o fa-fw"></i> 系统管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">

                                <li>
                                    <a href="userlist.html">用户管理</a>
                                </li>
                                <li>
                                    <a href="editpassword.html">修改密码</a>
                                </li>
                                <li>
                                    <a href="log.html">日志管理</a>
                                </li>
                                <li>
                                    <a href="login.html">退出系统</a>
                                </li>
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                    </ul>
                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </nav>

        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading row">
                            <div class="col-sm-6"> 当前位置: 库存管理 >进货计划</div>
                            <div class="col-sm-6">
                                <div class="optiondiv"><button type="button" class="btn btn-primary btn-sm"
                                        id="btncheck">审核</button>&nbsp;<button type="button"
                                        class="btn btn-primary btn-sm" id="btncreate">新增</button>&nbsp;<button
                                        type="button" class="btn btn-primary btn-sm"
                                        id="btnedit">编辑</button>&nbsp;<button type="button"
                                        class="btn btn-primary btn-sm" id="btndelete">删除</button></div>
                            </div>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">

                            <table width="100%" class="table table-striped table-bordered table-hover"
                                id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th class="center"><input type="checkbox" id="cball" /></th>
                                        <th class="center">单据编号</th>
                                        <th class="center">时间</th>
                                        <th class="center">金额</th>
                                        <th class="center">状态</th>
                                        <th class="center">备注</th>
                                    </tr>
                                </thead>
                                <tbody id="stocklist">

                                </tbody>
                            </table>
                            <!-- /.table-responsive -->
                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="dataTables_info" id="dataTables-example_info" role="status"
                                        aria-live="polite">显示第 1 至 5 项记录，共 5 项</div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="dataTables_paginate paging_simple_numbers"
                                        id="dataTables-example_paginate">
                                        <ul class="pagination">
                                            <!-- <li class="paginate_button previous disabled"
                                                aria-controls="dataTables-example" tabindex="0"
                                                id="dataTables-example_previous"><a href="#">上页</a></li>
                                            <li class="paginate_button active" aria-controls="dataTables-example"
                                                tabindex="0"><a href="#">1</a></li>
                                            <li class="paginate_button next disabled" aria-controls="dataTables-example"
                                                tabindex="0" id="dataTables-example_next"><a href="#">下页</a></li> -->
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>

                <!-- /.col-lg-12 -->
            </div>



        </div>


    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="../js/template-web.js" type="text/javascript" charset="utf-8"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="../vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="../vendor/metisMenu/metisMenu.min.js"></script>

    <!-- DataTables JavaScript -->
    <script src="../vendor/datatables/js/jquery.dataTables.min.js"></script>
    <script src="../vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="../vendor/datatables-responsive/dataTables.responsive.js"></script>

    <script src="../dist/js/sb-admin-2.js"></script>
    <script src="../dist/js/sea.js"></script>
    <script type="text/template" id="tmpl">
        <!-- 创建模板标签，进行遍历 -->
        {{each data as value index}}
        <tr class="odd gradeX">
            <td class="center"><input type="checkbox" class="ischeck" value="{{value._id}}" /></td>
            <td>{{value.number}}</td>
            <td>{{value.newtime}}</td>
            <td>{{value.money}}</td>
            {{if value.isflag=="已审核"}}
            <td><span>{{value.isflag}}</span></td>
            {{/if}}
            {{if value.isflag=="未审核"}}
            <td><span class="colorred">{{value.isflag}}</span></td>
            {{/if}}
            <td>{{value.remarks}}</td>
        </tr>
        {{/each}}
    </script>
    <script>
        showpage();
        window.page = 1;
        var allcount = 0;
        var pagenumber;
        $.get("/stock/count", function (data) {
            allcount = data.count; //获取到数组对象的长度，数组的长度
            pagenumber = Math.ceil(allcount / 3); //每页分3条，计算出可分多少页
            var html = '';
            var prevhtml = `<li class="paginate_button previous " aria-controls="dataTables-example"
                 id="dataTables-example_previous"><a href="#">上页</a></li>`;
            for (let i = 0; i < pagenumber; i++) {
                html
                    += '<li class="paginate_button paginateuser"><a class="" href="javascript:;">' + (i + 1) +
                    '</a> </li>'
            }
            var nexthtml = `<li class="paginate_button next " aria-controls="dataTables-example"
                id="dataTables-example_next"><a href="#">下页</a></li>`;

            var allhtml = prevhtml + html + nexthtml;
            $(".pagination").html(allhtml)
        })

        // 网页加载的时候开始渲染数据
        function showpage(n = 1) {
            $.get("/stock/stocklist", {
                n
            }, function (data) {
                var html = template("tmpl", {
                    data
                })
                $("#stocklist").html(html)
            })
        }

        window.onload = function () {
            $(".paginateuser")[0].className = "paginate_button paginateuser active";
            $(".paginateuser").click(function () {
                //获取当前标签中的数字
                var num = $(this).text();
                $(this).addClass("active").siblings().removeClass("active");
                num = parseInt(num);
                //console.log(num)
                showpage(num)
            })
            //下一页
            $("#dataTables-example_next").click(function () {
                var a = $(this).parent().find(".active").text();

                // console.log(a)

                if (a < pagenumber) {
                    a = parseInt(a);
                    $(".paginateuser").removeClass("active");
                    $(".paginateuser")[a].className = "paginate_button paginateuser active";
                    // console.log(a)
                    showpage(a + 1);
                } else {
                    alert("已到最后一页")
                }
            })
            //上一页
            $("#dataTables-example_previous").click(function () {
                var b = $(this).parent().find(".active").text();
                if (b > 1) {
                    b = parseInt(b);
                    $(".paginateuser").removeClass("active");
                    $(".paginateuser")[b - 2].className = "paginate_button paginateuser active";
                    // console.log(b)
                    showpage(b - 1);
                } else {
                    alert("这是第一页")
                }
            })
        }









        //  	$("#btndelete").click(function () {
        //  		$(".gradeX").each(function (i,v) {
        //  			var flag = $(v).find("input").prop("checked");
        //  			if (flag) {
        //  				$(this).closest("tr").remove();
        //  			}
        //  		})
        //  	})
        $("#cball").click(function () {
            $("input[type='checkbox']").not(this).prop("checked", $(this).prop("checked"));
        });

        seajs.config({
            alias: {
                "jquery": "jquery-1.10.2.js"
            }
        });

        seajs.use(['jquery', 'dialog-plus'], function ($, dialog) {
            //增加
            $('#btncreate').on('click', function () {
                location.href = "receiptplanadd.html";
            });
            //修改
            $('#btnedit').on('click', function () {
                var onlyi = 0;
                var editid;
                $(".ischeck").each(function (i, v) {
                    if ($(this).prop("checked")) {
                        onlyi++;
                        editid = $(this).val()
                    }
                })
                if (onlyi == 1) {
                    location.href = "receiptplandit.html#id=" + editid
                } else if (onlyi == 0) {
                    alert("请选择一条数据......")
                } else {
                    alert("只能选择一条数据......")
                }
            });


            //删除
            $("#btndelete").click(function () {
                var iis = 0;
                var checkarr = [];
                // var d = dialog({
                //     title: '温馨提示',
                //     content: '删除后不能恢复,确定删除吗',
                //     okValue: '确定',
                //     ok: function () {

                //     },
                //     cancelValue: '取消',
                //     cancel: function () {}
                // });
                // d.show();

                //用于判断是否有选中值
                $(".ischeck").each(function (i, v) {
                    if ($(this).prop("checked")) {
                        iis++;
                    }
                })
                //判断是否选中列表
                if (iis > 0) {

                    $(".ischeck").each(function (i, v) {

                        if ($(this).prop("checked")) {
                            checkarr.push($(this).val()); //将所有的id值传入空数组
                        }
                    })
                    // console.log(checkarr)//得到id值
                    $.get("/stock/deletemore", {
                        data: checkarr
                    }, function (data) {
                        if (data = "1") {
                            alert("删除成功....")
                            showpage();
                        } else {
                            alert("删除失败....")
                            showpage();
                        }
                    })
                } else {
                    alert("请选择数据......")
                }
            });

        });
        //审核
        $('#btncheck').on('click', function () {
            var iis = 0;
            var editidarr = [];
            $(".ischeck").each(function (i, v) {
                if ($(this).prop("checked")) {
                    iis++;
                }
            });
            if (iis > 0) {
                $(".ischeck").each(function (i, v) {
                    if ($(this).prop("checked")) { //如果选中就向空数组里面添加id值
                        editidarr.push($(this).val()); //向空数组中添加id值
                    }
                })
                //console.log(editidarr)
                //根据ID向后台发起请求
                $.get("/stock/statemore", {
                    data: editidarr
                }, function (data) {
                    alert("审核开始，请确定")
                    //console.log(data)
                    if (data == 1) {
                        alert("审核成功，已在备货中...");
                        showpage();
                    } else {
                        alert("审核失败")
                    }
                })
            } else {
                alert("请选择审核数据")
            }
        });
    </script>



</body>

</html>